#include "helpsymbol.h"

HelpSymbol::HelpSymbol(std::string id, int x, int y, int size_x, int size_y, ALLEGRO_FONT* label_font,
		std::string label, const unsigned char label_color[3], std::string graphic)
		: GuiElement(id, x, y, size_x, size_y)
{
	m_graphic = graphic;
	m_label_font = label_font;
	m_label = label;
	m_label_color = al_map_rgb(label_color[0], label_color[1], label_color[2]);

	m_on_symbol = false;
}

HelpSymbol::~HelpSymbol()
{
	al_destroy_font(m_label_font);
}

void HelpSymbol::MouseAxisChange(int x, int y)
{
	m_on_symbol = false;
	if (x >= m_x && x < m_x + m_size_x && y >= m_y && y < m_y + m_size_y)
		m_on_symbol = true;
}

void HelpSymbol::Draw()
{
	// Draw the symbol.
	ALLEGRO_BITMAP* graphic = allegro_bitmap_resource_manager.GetResource(m_graphic);
	al_draw_scaled_bitmap(graphic, 0, 0, al_get_bitmap_width(graphic), al_get_bitmap_height(graphic),
		m_x, m_y, m_size_x, m_size_y, NULL);

	// Draw the text if it is set.
	if (m_label != "" && m_on_symbol)
	{
		// Draw the text on the top layer so that it doesn't disappear under other gui elements.
		al_set_target_bitmap(System::GetInstance()->game()->top_layer());
		al_draw_text(m_label_font, m_label_color, m_x + m_size_x, m_y, NULL, m_label.c_str());
		al_set_target_bitmap(al_get_backbuffer(System::GetInstance()->display()));
	}
}